package manage;

import logIn.MysqlConnectionTool;

import javax.swing.*;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 管理员查看库存信息界面
 * @Author Jian Chen long
 * @Date 2021/6/18 10:34
 */
public class selectInhouse extends JFrame {
    private JScrollPane pane = new JScrollPane();

    private JTextArea select = new JTextArea();

    public selectInhouse(){
        pane.setViewportView(select);
        select.setEditable(false);
        this.add(pane);
        this.setTitle("仓库物资信息");
        select.setText("编号\t" + "型号\t" + "品牌\t" + "数量\t" + "价格\t" + "时间\n");
        this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        this.setSize(600,220);
        this.setLocationRelativeTo(null);
        this.setResizable(false);

        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try{
            conn = MysqlConnectionTool.getConnection();
            // 获取数据库操作对象
            String sql = "select * from inhouse";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()){
                select.append(rs.getString("inno") + "\t"
                        + rs.getString("inname") + "\t"
                        + rs.getString("inbrand") + "\t"
                        + rs.getString("incount") + "\t"
                        + rs.getString("inprice") + "\t"
                        + rs.getString("intime") + "\n");
            }
        }catch (Exception E){
            JOptionPane.showMessageDialog(null,"查询失败,请重试");
            return;
        }finally {
            MysqlConnectionTool.close(conn,ps,rs);
        }
    }
}
